package com.hema.auction.widget.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hema.auction.R;
import com.hema.auction.bean.GoodsInfo;
import com.hema.auction.utils.GlideUtils;
import com.hema.auction.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 描述:主页公告栏下面的最新商品
 * 作者:john
 */
public class IndexNewsGoodsView extends LinearLayout {

    @BindView(R.id.iv_img)
    ImageView ivImg;
    @BindView(R.id.iv_deal)
    ImageView ivDeal;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    public IndexNewsGoodsView(Context context) {
        super(context);
        init();
    }

    public IndexNewsGoodsView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public IndexNewsGoodsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        ButterKnife.bind(this, LayoutInflater.from(getContext()).inflate(R.layout.layout_index_news_goods, this));
    }

    public void setData(GoodsInfo info) {
        GlideUtils.load(getContext(), info.getImg(), ivImg);
        tvTitle.setText(info.getOwnerName());
        if (!Utils.isEmpty(info.getFinalPrice()))
            tvPrice.setText(Utils.priceUnitFormat(getContext(), info.getFinalPrice()));
    }
}
